//
//  XJLabelTextFieldCell.m
//  XinJiangMall
//
//  Created by RaoBo on 2018/5/21.
//  Copyright © 2018年 Tzyang. All rights reserved.
//

#import "XJLabelTextFieldCell.h"
@interface XJLabelTextFieldCell()<UITextFieldDelegate>
@property(nonatomic, strong) UILabel *leftLabel;
@property(nonatomic, strong) UITextField *rightTextField;

@end

@implementation XJLabelTextFieldCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        [self setupSubView];
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;

    }
    return self;
}
- (void)setupSubView {
    [self.contentView addSubview:self.leftLabel];
    [self.contentView addSubview:self.rightTextField];
}

- (UILabel *)leftLabel {
    if (!_leftLabel) {
        _leftLabel = [UILabel new];
    }
    return _leftLabel;
}

- (UITextField *)rightTextField {
    if (!_rightTextField) {
        _rightTextField = [UITextField new];
        _rightTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
        
        _rightTextField.delegate = self;
    }
    return _rightTextField;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(15);
        make.top.bottom.equalTo(self.contentView);
        make.width.mas_equalTo(100);
    }];
    
    [self.rightTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self);
        make.left.equalTo(self.leftLabel.mas_right).offset(15);
    }];
}

#pragma mark - 接口
- (void)configureLabelTextFieldCellWithName:(NSString *)name contentStr:(NSString *)contentStr placeholder:(NSString *)placehodler {
    self.leftLabel.text = name;
    
    self.rightTextField.text = contentStr;
    self.rightTextField.placeholder = placehodler;
}

#pragma mark - UITextFieldDelegate
//UITextFieldDelegate
//- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
//    return YES;
//}

- (void)textFieldDidEndEditing:(UITextField *)textField {
    if (self.labelTextFieldCellBlock) {
        self.labelTextFieldCellBlock(textField.text);
    }
}




@end
